package com.iring.dao.vos;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.iring.domain.vos.customer.Customer;
import com.iring.domain.vos.customer.ReturnUser;
import com.iring.domain.vos.customer.UserRequest;
import com.iring.exception.ParamInvalidException;

/**
 * 将vos的数据进行提取,返回用户对象进行现金结算
 *
 * @author wanggan
 */
@Component
public class UserVosDao extends BaseVosDao<ReturnUser> {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private static final String GET_CUSTOMER = "GetCustomer";

    /**
     * 自动传入参数进行调用
     *
     * @param userRequest
     *            获取用户信息的参数
     * @return vos用户信息{@link Customer}
     */
    public Customer getVosCustomer(UserRequest userRequest) {
        String result = util.postData(GET_CUSTOMER, userRequest);
        ReturnUser returnUser = convertToObject(result, ReturnUser.class);
        if(null == returnUser){
            return null;
        }
        double retCode = returnUser.getRetCode();
        if (0.0 == retCode) {// 如果正确
            if (returnUser.getInfoCustomers().size() == 0) {
                return null;
            }
            return returnUser.getInfoCustomers().get(0);
        } else {
            logger.info("error returnUser={}", returnUser);
            throw new ParamInvalidException(returnUser.getException());
        }
    }

}
